package com.jbp.service;

import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.extension.service.IService;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.jbp.dao.RoomRecomendDao;
import com.jbp.model.Room;
import com.jbp.model.RoomRecomend;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import com.jbp.utils.PageUtils;
import com.jbp.utils.Query;

import java.util.ArrayList;
import java.util.List;
import java.util.Map;
import java.util.stream.Collectors;

@Service
public class RoomRecomendService extends ServiceImpl<RoomRecomendDao, RoomRecomend> implements IService<RoomRecomend> {

    @Autowired
    private RoomService roomService;

    public PageUtils queryPage(Map<String, Object> params) {
        QueryWrapper<RoomRecomend> queryWrapper = new QueryWrapper<>();
        if (params.get("id") != null) {
            queryWrapper.like("id",params.get("id"));
        }
        if (params.get("roomId") != null) {
            queryWrapper.like("room_id",params.get("roomId"));
        }
        if (params.get("inx") != null) {
            queryWrapper.like("inx",params.get("inx"));
        }
        if (params.get("fromDate")!=null) {
            queryWrapper.ge("create_time", params.get("fromDate"));
        }
        if (params.get("toDate")!=null) {
            queryWrapper.le("DATE_FORMAT(create_time,   '%Y-%m-%d')", params.get("toDate"));
        }
        queryWrapper.orderByDesc("id");
        IPage<RoomRecomend> page = this.page(
            new Query<RoomRecomend>().getPage(params), queryWrapper
        );
        return new PageUtils(page);
    }
}